package com.lelouch.concurrency.theartofconcurrency.interrupt;

/**
 * @author lcy
 * @create 2018-08-23 11:14
 */
public class InterruptExample1 {
    public static void main(String[] args) {
        NRunnable run=new NRunnable();
        Thread t=new Thread(run);
        t.start();
        System.out.println("is start.......");
        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {

        }
        run.cancel();
        System.out.println("cancel ..."+System.currentTimeMillis());
    }

    public static class NRunnable implements Runnable
    {
        public boolean isCancel=false;

        @Override
        public void run() {
            while(!isCancel)
            {
                System.out.println("我没有种中断");
                try {
                    Thread.sleep(10000);
                } catch (InterruptedException e) {

                }
            }
            System.out.println("我已经结束了..."+System.currentTimeMillis());
        }

        public void cancel()
        {
            this.isCancel=true;
        }

    }



}
